home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 990 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.6 KB

  1. Path: news1.h1.usa.pipeline.com!usenet
  2. From: grantp@usa.pipeline.com
  3. Newsgroups: comp.lang.c++
  4. Subject: Cost of virtual dispatch - was Re: Faster FILE subroutines in standard C?
  5. Date: 8 Jan 1996 18:51:50 GMT
  6. Organization: Kalevi, Inc
  7. Message-ID: <4crp46$n5s@news1.usa.pipeline.com>
  8. References: <4crl7s$h4r@gold.datalytics.com>
  9. NNTP-Posting-Host: pipe4.h1.usa.pipeline.com
  10. X-PipeUser: grantp
  11. X-PipeHub: usa.pipeline.com
  12. X-PipeGCOS: (Pete)
  13. X-Newsreader: Pipeline USA v3.3.0
  14.  
  15. On Jan 08, 1996 17:45:32 in article <Re: Faster FILE subroutines in
  16. standard C?>, 'Rob Stewart <stew@datalytics.com>' wrote: 
  17.  
  18. >As soon as you make use of virtual base classes, polymorphism,  
  19. >etc., your code runs slower. 
  20.  
  21. This has been discussed previously more than once in this  
  22. newsgroup and it has been shown that EQUIVALENT C++ 
  23. code is not slower.  If you compare with a static function 
  24. call to a virtual one, there's a price to pay -- albeit a very 
  25. small one.  But equivalent C code must select the appropriate 
  26. function to call, typically using a switch statement.  The 
  27. combination of selection by switch and calling a static  
  28. function is not slower than a call to a virtual function. 
  29.  
  30. >                                  The advantage is type safety,  
  31. >flexibility, and ease of expression.  There are always  
  32. >tradeoffs to be made. 
  33.  
  34. Previous discussion also pointed out that even if considering 
  35. only the function calls themselves, this 'tradeoff' is negligible 
  36. in comparison with the overall program execution.   
  37. A programmer would be wise to direct his/her efforts towards 
  38. improving algorithms rather than the cost of late binding. 
  39.  
  40. -- 
  41.  
  42. Pete 
  43.  
  44.  
  45.  
  46.  
  47.  
  48.